********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************

****
** Open ANES 1992-1996 Panel
****

set more off

* use "anes_mergedfile_1992to1997.dta"

********************************************************************************

****
** Data cleaning and recoding
****

* Case ID
gen id92 = VID92 
gen id94 = VID94 
gen id96 = VID96

keep if id92 != . & id96 != .


* Weight
gen weight92 = V923009
gen weight94 = V940005 
gen weight96 = V960004


* Party identification
gen pid92 = V923634 - 3
replace pid92 = . if pid92 > 3
gen pid94 = V940655 - 3
replace pid94 = . if pid94 > 3
gen pid96 = V960420 - 3
replace pid96 = . if pid96 > 3

gen rep92 = 1 if pid92 > 0 & pid92 < .
replace rep92 = 0 if pid92 < 0
gen rep94 = 1 if pid94 > 0 & pid94 < .
replace rep94 = 0 if pid94 < 0
gen rep96 = 1 if pid96 > 0 & pid96 < .
replace rep96 = 0 if pid96 < 0


* Party ID strength
gen pidstrength92 = 3 if abs(pid92) == 3
replace pidstrength92 = 2 if abs(pid92) == 2
replace pidstrength92 = 1 if abs(pid92) == 1
replace pidstrength92 = 0 if abs(pid92) == 0

gen pidstrength94 = 3 if abs(pid94) == 3
replace pidstrength94 = 2 if abs(pid94) == 2
replace pidstrength94 = 1 if abs(pid94) == 1
replace pidstrength94 = 0 if abs(pid94) == 0

gen pidstrength96 = 3 if abs(pid96) == 3
replace pidstrength96 = 2 if abs(pid96) == 2
replace pidstrength96 = 1 if abs(pid96) == 1
replace pidstrength96 = 0 if abs(pid96) == 0


* Ideology
gen ideo92 = V923509 - 4
replace ideo92 = . if abs(ideo92) > 3 
gen ideo94 = V940839 - 4
replace ideo94 = . if abs(ideo94) > 3 
gen ideo96 = V960365 - 4
replace ideo96 = . if abs(ideo96) > 3 

gen conserv92 = 1 if ideo92 > 0 & ideo92 < .
replace conserv92 = 0 if ideo92 < 0
gen conserv94 = 1 if ideo94 > 0 & ideo94 < .
replace conserv94 = 0 if ideo94 < 0
gen conserv96 = 1 if ideo96 > 0 & ideo96 < .
replace conserv96 = 0 if ideo96 < 0


* Ideological strength
gen ideostrength92 = 3 if abs(ideo92) == 3
replace ideostrength92 = 2 if abs(ideo92) == 2
replace ideostrength92 = 1 if abs(ideo92) == 1
replace ideostrength92 = 0 if abs(ideo92) == 0

gen ideostrength94 = 3 if abs(ideo94) == 3
replace ideostrength94 = 2 if abs(ideo94) == 2
replace ideostrength94 = 1 if abs(ideo94) == 1
replace ideostrength94 = 0 if abs(ideo94) == 0

gen ideostrength96 = 3 if abs(ideo96) == 3
replace ideostrength96 = 2 if abs(ideo96) == 2
replace ideostrength96 = 1 if abs(ideo96) == 1
replace ideostrength96 = 0 if abs(ideo96) == 0


* Sorting
replace ideostrength92 = ideostrength92 + 1
replace pidstrength92 = pidstrength92 + 1
gen sorting92 = abs(pid92 - (-1 * ideo92)) * ideostrength92 * pidstrength92

replace ideostrength94 = ideostrength94 + 1
replace pidstrength94 = pidstrength94 + 1
gen sorting94 = abs(pid94 - (-1 * ideo94)) * ideostrength94 * pidstrength94

replace ideostrength96 = ideostrength96 + 1
replace pidstrength96 = pidstrength96 + 1
gen sorting96 = abs(pid96 - (-1 * ideo96)) * ideostrength96 * pidstrength96


* Education (ranges from 1-7)
gen edu92 = V923908
replace edu92 = . if edu92 >= 8
replace edu92 = . if edu92 < 1
label define edulab 1 "8 grades or less" 2 "9-12 grades" 3 "High school" ///
	4 "HS + non-academic training" 5 "Some college" 6 "BA" 7 "Advanced"
label values edu edulab


* Family income (1-24)
gen income92 = V924104
replace income92 = . if income > 24


* Race 
gen race92 = V924202
replace race92 = . if race92 == 9

gen white92 = 0
replace white92 = 1 if race92 == 1

gen black92 = 0
replace black92 = 1 if race92 == 2


* Gender (1=female)
gen female92 = V924201 - 1
replace female92 = . if female92 < 0
replace female92 = . if female92 > 1
label define genderlab 0 "Male" 1 "Female"
label values female92 genderlab


* Age (number of years) 
gen age92 = V923903
replace age92 = . if age92 > 91
replace age92 = . if age92 < 17


* Region
gen south92 = .
replace south92 = 0 
replace south92 = 1 if V923014 == 3
label define southern 0 "0 Non-South" 1 "1 South"
label values south southern


* Church attendance
gen church92 = V923821
replace church92 = . if church92 < 1
recode church92 (5=0) (4=1) (3=2) (2=3) (1=4)


* Interest in campaigns 
gen interest92 = V925102
replace interest92 = . if interest92 > 5
replace interest92 = . if interest92 < 1
recode interest92 (1=3) (3=2) (5=1)
label define interestlab 1 "Not much interested" ///
	2 "Somewhat interested" 3 "Very much interested"
label values interest interestlab


* Interviewer information assessment
gen info92 = V924205
replace info92 = . if info92 > 9
recode info92 (5=0) (4=1) (3=2) (2=3) (1=4)


* Party feeling thermometers
gen reptherm92 = V923318
replace reptherm92 = . if reptherm92 > 100
gen demtherm92 = V923317
replace demtherm92 = . if demtherm92 > 100
gen partydifftherm92 = abs(demtherm92 - reptherm92)

gen reptherm94 = V940302
replace reptherm94 = . if reptherm94 > 100
gen demtherm94 = V940301
replace demtherm94 = . if demtherm94 > 100
gen partydifftherm94 = abs(demtherm94 - reptherm94)

gen reptherm96 = V960293
replace reptherm96 = . if reptherm96 > 100
gen demtherm96 = V960292
replace demtherm96 = . if demtherm96 > 100
gen partydifftherm96 = abs(demtherm96 - reptherm96)


* Candidate feeling thermometers
gen rcandtherm92 = V923305
replace rcandtherm92 = . if rcandtherm92 > 100
gen dcandtherm92 = V923306
replace dcandtherm92 = . if dcandtherm92 > 100
gen diffcandtherm92 = abs(dcandtherm92 - rcandtherm92)

gen rcandtherm96 = V960273
replace rcandtherm96 = . if rcandtherm96 > 100
gen dcandtherm96 = V960272
replace dcandtherm96 = . if dcandtherm96 > 100
gen diffcandtherm96 = abs(dcandtherm96 - rcandtherm96)


* Ideological group feeling thermometers
gen contherm92 = V925319
replace contherm92 = . if contherm92 > 100
gen libtherm92 = V925326
replace libtherm92 = . if libtherm92 > 100
gen diffideotherm92 = abs(libtherm92 - contherm92)

gen contherm94 = V940306
replace contherm94 = . if contherm94 > 100
gen libtherm94 = V940311
replace libtherm94 = . if libtherm94 > 100
gen diffideotherm94 = abs(libtherm94 - contherm94)

gen contherm96 = V961031
replace contherm96 = . if contherm96 > 100
gen libtherm96 = V961032
replace libtherm96 = . if libtherm96 > 100
gen diffideotherm96 = abs(libtherm96 - contherm96)


* Affective polarization
factor diffideotherm92 diffcandtherm92 partydifftherm92, ipf
alpha diffideotherm92 diffcandtherm92 partydifftherm92, gen(affectpol92)

factor diffideotherm96 diffcandtherm96 partydifftherm96, ipf
alpha diffideotherm96 diffcandtherm96 partydifftherm96, gen(affectpol96)


* Party ideology
gen repideo92 = V923517
replace repideo92 = . if repideo92 < 1
replace repideo92 = . if repideo92 > 7
gen demideo92 = V923518
replace demideo92 = . if demideo92 < 1
replace demideo92 = . if demideo92 > 7
gen pdiffideo92 = abs(repideo92 - demideo92)

gen repideo96 = V960380
replace repideo96 = . if repideo96 < 1
replace repideo96 = . if repideo96 > 7
gen demideo96 = V960379
replace demideo96 = . if demideo96 < 1
replace demideo96 = . if demideo96 > 7
gen pdiffideo96 = abs(repideo96 - demideo96)


* Government spending and services
gen selfservice92 = V923701
replace selfservice92 = . if selfservice92 < 1
replace selfservice92 = . if selfservice92 >= 8
recode selfservice92 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)
label values selfservice92 servicelab

gen repservice92 = V923702
replace repservice92 = . if repservice92 < 1
replace repservice92 = . if repservice92 >= 8
recode repservice92 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)

gen demservice92 = V923703
replace demservice92 = . if demservice92 < 1
replace demservice92 = . if demservice92 >= 8
recode demservice92 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)

gen pdiffservice92 = abs(repservice92 - demservice92)


gen selfservice96 = V960450
replace selfservice96 = . if selfservice96 < 1
replace selfservice96 = . if selfservice96 >= 8
recode selfservice96 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)

gen repservice96 = V960455
replace repservice96 = . if repservice96 < 1
replace repservice96 = . if repservice96 >= 8
recode repservice96 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)

gen demservice96 = V960453
replace demservice96 = . if demservice96 < 1
replace demservice96 = . if demservice96 >= 8
recode demservice96 (1=3) (2=2) (3=1) (4=0) (5=-1) (6=-2) (7=-3)

gen pdiffservice96 = abs(repservice96 - demservice96)


* Defense spending
gen selfdefense92 = V923707
replace selfdefense92 = . if selfdefense92 < 1
replace selfdefense92 = . if selfdefense92 >= 8
recode selfdefense92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define defenselab -3 "Greatly decrease defense spending" ///
	3 "Greatly increase defense spending"
label values selfdefense92 defenselab

gen repdefense92 = V923708
replace repdefense92 = . if repdefense92 < 1
replace repdefense92 = . if repdefense92 >= 8
recode repdefense92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen demdefense92 = V923709
replace demdefense92 = . if demdefense92 < 1
replace demdefense92 = . if demdefense92 >= 8
recode demdefense92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffdefense92 = abs(repdefense92 - demdefense92)


gen selfdefense96 = V960463
replace selfdefense96 = . if selfdefense96 < 1
replace selfdefense96 = . if selfdefense96 >= 8
recode selfdefense96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen repdefense96 = V960469
replace repdefense96 = . if repdefense96 < 1
replace repdefense96 = . if repdefense96 >= 8
recode repdefense96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen demdefense96 = V960466
replace demdefense96 = . if demdefense96 < 1
replace demdefense96 = . if demdefense96 >= 8
recode demdefense96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffdefense96 = abs(repdefense96 - demdefense96)


* Health insurance
gen selfinsure92 = V923716
replace selfinsure92 = . if selfinsure92 < 1
replace selfinsure92 = . if selfinsure92 > 7
recode selfinsure92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define insurelab -3 "Government insurance plan" 3 "Private insurance plan"
label values selfinsure92 insurelab


gen selfinsure96 = V960479
replace selfinsure96 = . if selfinsure96 < 1
replace selfinsure96 = . if selfinsure96 > 7
recode selfinsure96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen repinsure96 = V960481
replace repinsure96 = . if repinsure96 < 1
replace repinsure96 = . if repinsure96 > 7
recode repinsure96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen deminsure96 = V960480
replace deminsure96 = . if deminsure96 < 1
replace deminsure96 = . if deminsure96 > 7
recode deminsure96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffinsure96 = abs(repinsure96 - deminsure96)


* Guarenteed jobs
gen selfjobs92 = V923718
replace selfjobs92 = . if selfjobs92 < 1
replace selfjobs92 = . if selfjobs92 >= 8
recode selfjobs92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define jobslab -3 "Government see to job and good standard of living" ///
	3 "Government let each person get ahead on his own"
label values selfjobs92 jobslab

gen repjobs92 = V923719
replace repjobs92 = . if repjobs92 < 1
replace repjobs92 = . if repjobs92 >= 8
recode repjobs92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen demjobs92 = V923720
replace demjobs92 = . if demjobs92 < 1
replace demjobs92 = . if demjobs92 >= 8
recode demjobs92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffjobs92 = abs(repjobs92 - demjobs92)


gen selfjobs96 = V960483
replace selfjobs96 = . if selfjobs96 < 1
replace selfjobs96 = . if selfjobs96 >= 8
recode selfjobs96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen repjobs96 = V960485
replace repjobs96 = . if repjobs96 < 1
replace repjobs96 = . if repjobs96 >= 8
recode repjobs96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen demjobs96 = V960484
replace demjobs96 = . if demjobs96 < 1
replace demjobs96 = . if demjobs96 >= 8
recode demjobs96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffjobs96 = abs(repjobs96 - demjobs96)


* Aid to blacks
gen selfaid92 = V923724
replace selfaid92 = . if selfaid92 == 0
replace selfaid92 = . if selfaid92 >= 8
recode selfaid92 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)
label define aidlab -3 "Government should help minority groups" ///
	3 "Minority groups should help themselves"
label values selfaid92 aidlab


gen selfaid96 = V960487
replace selfaid96 = . if selfaid96 == 0
replace selfaid96 = . if selfaid96 >= 8
recode selfaid96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen repaid96 = V960492
replace repaid96 = . if repaid96 == 0
replace repaid96 = . if repaid96 >= 8
recode repaid96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen demaid96 = V960490
replace demaid96 = . if demaid96 == 0
replace demaid96 = . if demaid96 >= 8
recode demaid96 (1=-3) (2=-2) (3=-1) (4=0) (5=1) (6=2) (7=3)

gen pdiffaid96 = abs(repaid96 - demaid96)


* Perceived polarization
factor pdiffideo92 pdiffservice92 pdiffdefense92 ///
	pdiffjobs92, ipf
alpha pdiffideo92 pdiffservice92 pdiffdefense92 ///
	pdiffjobs92, gen(ppol92)

factor pdiffideo96 pdiffjobs96 pdiffdefense96 ///
	pdiffservice96, ipf	
alpha pdiffideo96 pdiffjobs96 pdiffdefense96 ///
	pdiffservice96, gen(ppol96) 

* Issue extremity
gen issex1 = abs(selfdefense92)
gen issex2 = abs(selfservice92)	
gen issex3 = abs(selfaid92)	
gen issex4 = abs(selfinsure92)	
gen issex5 = abs(selfjobs92)	
	
alpha issex1-issex5, gen(issextreme92)

********************************************************************************
	
****
** Supplemental Appendix Analyses
****	

foreach v of var ppol96 ppol92 affectpol96 affectpol92 pidstrength92 ///
	ideostrength92 interest92 info92 edu92 age92 income92{
	su `v', meanonly 
	replace `v' = (`v' - r(min))/(r(max) - r(min)) 
}	


* Section 3 of Supplemental Appendix
sem (ppol96 <- ppol92 affectpol92) ///
	(affectpol96 <- affectpol92 ppol92) if rep96 != ., standardized

sem (ppol96 <- ppol92 affectpol92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(affectpol96 <- affectpol92 ppol92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized	
	
mrobust reg ppol96 affectpol92 ppol92 pidstrength92 ideostrength92 ///
	issextreme92 interest92 info92 edu92 age92 income92 female92 ///
	black92 south92 if rep96 != .
	
mrobust reg affectpol96 ppol92 affectpol92 pidstrength92 ideostrength92 ///
	issextreme92 interest92 info92 edu92 age92 income92 female92  ///
	black92 south92 if rep96 != .
	
	
* Table A6 in Supplemental Appendix
sem (ppol96 <- ppol92 diffideotherm92 diffcandtherm92 partydifftherm92 /// 
	pidstrength92 ideostrength92 issextreme92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(diffideotherm96 diffcandtherm96 partydifftherm96 <- diffideotherm92 ///
	diffcandtherm92 partydifftherm92 ppol92 pidstrength92 ///
	ideostrength92 issextreme92  ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92), standardized
	
	
* Disagregating affective polarization scales
sem (ppol96 <- ppol92 partydifftherm92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(partydifftherm96 <- partydifftherm92 ppol92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized
	
sem (ppol96 <- ppol92 diffideotherm92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(diffideotherm96 <- diffideotherm92 ppol92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized	
	
sem (ppol96 <- ppol92 diffcandtherm92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(diffcandtherm96 <- diffcandtherm92 ppol92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized		
	
	
* Disagregating perceived polarization scales
sem (pdiffideo96 <- pdiffideo92 affectpol92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(affectpol96 <- affectpol92 pdiffideo92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized
	
sem (pdiffservice96 <- pdiffservice92 affectpol92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(affectpol96 <- affectpol92 pdiffservice92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized
	
sem (pdiffjobs96 <- pdiffjobs92 affectpol92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(affectpol96 <- affectpol92 pdiffjobs92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized
	
sem (pdiffdefense96 <- pdiffdefense92 affectpol92 pidstrength92 ideostrength92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92) ///
	(affectpol96 <- affectpol92 pdiffdefense92 pidstrength92 ideostrength92   ///
	interest92 info92 edu92 age92 income92 female92  ///
	black92 south92) if rep96 != ., standardized	
	

* Multicollinearity	
reg ppol96 ppol92 diffideotherm92 diffcandtherm92 partydifftherm92 /// 
	pidstrength92 ideostrength92 issextreme92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92
vif

reg diffideotherm96 ppol92 diffideotherm92 diffcandtherm92 partydifftherm92 /// 
	pidstrength92 ideostrength92 issextreme92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92
vif

reg diffcandtherm96 ppol92 diffideotherm92 diffcandtherm92 partydifftherm92 /// 
	pidstrength92 ideostrength92 issextreme92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92
vif

reg partydifftherm92 ppol92 diffideotherm92 diffcandtherm92 partydifftherm92 /// 
	pidstrength92 ideostrength92 issextreme92 ///
	interest92 info92 edu92 age92 income92 female92 ///
	black92 south92
vif

	
